<?php
namespace Modules\ShopApi\Services;
use Modules\AuthAdmin\Services\CommonService;
use Modules\ShopApi\Models\BaseApiModel;
class JuheService  
{
	private $mobile_key,$idcard_key; 
	public function __construct()
	{
		$this->mobile_key = env('JUHE_MOBILE_KEY',''); 
		$this->idcard_key = env('JUHE_IDCARD_KEY',''); 
	}  
	/**
     * @name  手机号码归属地
     */
    public function get_phone($phone)
    {
		$data = (new CommonService())->juhe_curl(
			'http://apis.juhe.cn/mobile/get',
			[
				'key' => $this->mobile_key,
				'phone' => $phone
			]
		);  
		return $this->ret_api($data,true);
    }
	/**
     * @name  身份证查询
     */
    public function get_idcard($idcard)
    {
		$data = (new CommonService())->juhe_curl(
			'http://apis.juhe.cn/idcard/index',
			[
				'key' => $this->idcard_key,  
				'cardno' => $idcard
			] 
		);    
		return $this->ret_api($data,true);
    }
	/**
     * @name  返回方法 
     */
	public function ret_api($data,$json = false){
		$BaseApiModel = new BaseApiModel();
		if($data){
			if($json){
				$data = json_decode($data,true);
			}
			if($data['error_code'] == '0'){  
				return $BaseApiModel->api_success(['data'=>$data]); 
			}
		}
		return $BaseApiModel->api_error();	 
	}
}
